import Vue from 'vue'
import router from 'vue-router'
import { Message } from "element-ui";
import 'element-ui/lib/theme-chalk/index.css'

//注册全局组件
Vue.use(router)
Vue.use(Message);

let a = null
export default a = new router({
    routes: [
        {
            path: '/',
            name: 'Show',
            component: () => import('@/components/Show.vue'),
            children: [
                //测试
                {
                    path: '/Test',
                    name: 'test',
                    component: () => import('@/components/test'),
                },
                //人事工作台
                {
                    path: '/Personneldesk',
                    name: 'Personneldesk',
                    component: () => import('@/components/workbench/Personneldesk'),
                },
                //员工假期
                {
                    path: '/holiday',
                    name: 'holiday',
                    component: () => import('@/components/holiday/Type'),
                },
                //请假记录表
                {
                    path: '/balance',
                    name: 'Balance',
                    component: () => import('@/components/holiday/Balance'),
                },
                //员工假期余额表
                {
                    path: '/leavedetail',
                    name: 'leavedetail',
                    component: () => import('@/components/holiday/LeaveDetail'),
                },
                //新建假期类型
                {
                    path: '/updatetype',
                    name: 'UpdateType',
                    component: () => import('@/components/holiday/updateType'),
                },
                //修改员工假期余额表
                {
                    path: '/updateBalance',
                    name: 'updateBalance',
                    component: () => import('@/components/holiday/updateBalance'),
                },

                //发起申请
                {
                    path: '/LaunchApplication',
                    name: 'LaunchApplication',
                    component: () => import('@/components/approver/LaunchApplication.vue'),
                },
                //审批中心 待处理  
                {
                    path: '/Pending',
                    name: 'Pending',
                    component: () => import('@/components/approver/Pending.vue'),
                },
                //审批中心 已处理 
                {
                    path: '/Processed',
                    name: 'Processed',
                    component: () => import('@/components/approver/Processed.vue'),
                },
                //我收到的
                {
                    path: '/Ireceived',
                    name: 'Ireceived',
                    component: () => import('@/components/approver/Ireceived.vue'),
                },
                //审批中心 我发起的 
                {
                    path: '/Iinitiated',
                    name: 'Iinitiated',
                    component: () => import('@/components/approver/Iinitiated.vue'),
                },
                //审批中心，请假 
                {
                    path: '/Leave',
                    name: 'Leave',
                    component: () => import('@/components/approver/Leave.vue'),
                },
                //审批中心，出差 
                {
                    path: '/Evection',
                    name: 'Evection',
                    component: () => import('@/components/approver/Evection.vue'),
                },
                //审批中心，加班
                {
                    path: '/Overtime',
                    name: 'Overtime',
                    component: () => import('@/components/approver/Overtime.vue'),
                },
                //审批中心，外出
                {
                    path: '/GoOut',
                    name: 'GoOut',
                    component: () => import('@/components/approver/GoOut.vue'),
                },
                //审批中心，详情页
                {
                    path: '/Particulars',
                    name: 'Particulars',
                    component: () => import('@/components/approver/Particulars.vue'),
                },
                //财务工作台
                {
                    path: '/Financialworkbench',
                    name: 'Financialworkbench',
                    component: () => import('@/components/workbench/Financialworkbench')
                },
                // 行政工作台
                {
                    path: '/Administrativeworkbench',
                    name: 'Administrativeworkbench',
                    component: () => import('@/components/workbench/Administrativeworkbench')

                },
                // 总经理工作台 
                {
                    path: '/GeneralManagerworkbench',
                    name: 'GeneralManagerworkbench',
                    component: () => import('@/components/workbench/GeneralManagerworkbench')

                },
                // 薪资
                {
                    path: '/SalaryCalculate',
                    name: 'SalaryCalculate',
                    component: () => import('@/components/salary/SalaryCalculate')

                },
                //添加薪资方案
                {
                    path: '/AddSalaryCalculate',
                    name: 'AddSalaryCalculate',
                    component: () => import('@/components/salary/AddSalaryCalculate')

                },
                 //薪资项目
                 {
                    path: '/PayrollItems',
                    name: 'PayrollItems',
                    component: () => import('@/components/salary/PayrollItems')

                },
                //操作日志
                {
                    path: '/operationlog',
                    name: 'operationlog',
                    component: () => import('@/components/setting/operationlog')
                },
                // 角色管理
                {
                    path: '/rolemanagement',
                    name: 'rolemanagement',
                    component: () => import('@/components/setting/rolemanagement')
                },
                // 角色管理 新增角色
                {
                    path: '/AddAndUpRole',
                    name: 'AddAndUpRole',
                    component: () => import('@/components/setting/addanduprole')
                },
                //消息通知
                {
                    path: '/messagenotification',
                    name: 'messagenotification',
                    component: () => import('@/components/setting/messagenotification')
                },
                {
                    path: '/Attendance',
                    name: 'Attendance',
                    component: () => import('@/components/attendance/attendanceIndex.vue')

                },
                // 补卡
                {
                    path: '/ReplacementCardIndex',
                    name: 'replacementCardIndex',
                    component: () => import('@/components/attendance/replacementCard/replacementCardIndex.vue')

                },
                // 新增补卡规则
                {
                    path: '/ReplacementCardAdd',
                    name: 'replacementCardAdd',
                    component: () => import('@/components/attendance/replacementCard/replacementCardAdd.vue')

                },
                //  地图测试
                {
                    path: "/Demo",
                    name: "demo",
                    component: () => import('@/components/attendance/replacementCard/demo.vue')
                },
                //  加班规则
                {
                    path: "/OvertimeIndex",
                    name: "overtimeIndex",
                    component: () => import('@/components/attendance/overtime/OvertimeIndex.vue')
                },
                //  新建加班规则
                {
                    path: "/OvertimeAdd",
                    name: "overtimeAdd",
                    component: () => import('@/components/attendance/overtime/OvertimeAdd.vue')
                },
                //候选人
                , {
                    path: '/Candidate',
                    name: 'Candidate',
                    component: () => import('@/components/recruit/Candidate')
                }
                //人才库
                , {
                    path: '/TalentPool',
                    name: 'TalentPool',
                    component: () => import('@/components/recruit/TalentPool')
                }
                //招聘管理 设置
                , {
                    path: '/Setting',
                    name: 'Setting',
                    component: () => import('@/components/recruit/Setting')
                }
                //简历数据
                , {
                    path: '/ResumeData',
                    name: 'ResumeData',
                    component: () => import('@/components/recruit/ResumeData')
                }
                //招聘概况
                , {
                    path: '/RecruitmentOverview',
                    name: 'RecruitmentOverview',
                    component: () => import('@/components/recruit/RecruitmentOverview')
                }
                //招聘漏斗
                , {
                    path: '/Recruitingfunnel',
                    name: 'Recruitingfunnel',
                    component: () => import('@/components/recruit/Recruitingfunnel')
                }
                //职位管理
                , {
                    path: '/PositionManagement',
                    name: 'PositionManagement',
                    component: () => import('@/components/recruit/PositionManagement')
                },
                //印章库
                {
                    path: '/Sealvault',
                    name: 'Sealvault',
                    component: () => import('@/components/seal/Sealvault')
                },
                //用章管理
                {
                    path: '/Managementbyseal',
                    name: 'Managementbyseal',
                    component: () => import('@/components/seal/Managementbyseal')
                },
                //资产列表
                {
                    path: '/PropertyList',
                    name: 'PropertyList',
                    component: () => import('@/components/property/PropertyList')
                },
                //添加资产
                {
                    path: '/AddProperty',
                    name: 'AddProperty',
                    component: () => import('@/components/property/AddProperty')
                },
                //公告管理
                {
                    path: '/notice',
                    name: 'notice',
                    component: () => import('@/components/notice/notice'),
                },
                 //信息公告
                 {
                    path: '/informationNotice',
                    name: 'informationNotice',
                    component: () => import('@/components/notice/informationNotice'),
                },
                //文档管理
                {
                    path: '/document',
                    name: 'document',
                    component: () => import('@/components/document/document'),
                },
                  //文档分类
                {
                    path: '/documentclass',
                    name: 'documentclass',
                    component: () => import('@/components/document/documentclass'),
                },
                //报销管理
                {
                    path: '/ReimbursementList',
                    name: 'ReimbursementList',
                    component: () => import('@/components/reimbursement/ReimbursementList')  
                },
                // 添加报销申请
                {
                    path: '/AddReimbursement',
                    name: 'AddReimbursement',
                    component: () => import('@/components/reimbursement/AddReimbursement')  
                },
            ]
        },
        {
            path: '/login',
            name: 'login',
            component: () => import('@/components/Login.vue'),
        },
        {
            path: '/register',
            name: 'register',
            component: () => import('@/components/Register.vue'),
        }
    ],
    mode: "history"

})

// 为路由对象添加路由导航守卫
a.beforeEach((to, from, next) => {
    if (to.path === '/login' || to.path === '/register') {  //  如果用户访问的是登录页面 直接放行
        return next();
    }

    let token = window.localStorage.getItem('token');  //  从LocalStorage中得到token
    const tokenStartTime = window.localStorage.getItem('tokenStartTime');  //   获取存储token的开始时间

    const timeOver = 1 * 3600 * 1000;  // 定义1个小时过期，让用户重新登录一下
    let date = new Date().getTime();  //  当前时间
    if (date - tokenStartTime > timeOver) {  //  如果大于说明是token过期了
        token = null;
        window.localStorage.removeItem("token");
        window.localStorage.removeItem("tokenStartTime");
    }

    // 如果没有token值 那么就跳转到'/login
    if (!token) {
        if (to.path == '/login') {
            return next();
        }
        Message({
            message: '登录失效，请重新登录',
            type: 'warning'
        });
        return next('/login');
    }

    // 如果有token则放行
    next();
})



